﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>方向条件-独立表单字段条件</title>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script src="../Admin.js" type="text/javascript"></script>

    <base target="_self" />
    <script type="text/javascript">
        function Esc() {
            if (event.keyCode == 27)
                window.close();
            return true;
        }

        var OperForString = null;
        var OperForNumber = null;
        //初始化页面函数.....
        $(function () {

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("StandAloneFrm_Init");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>加载失败:<br>" + data + "</font> .");
                return;
            }

            //转json.
            data = JSON.parse(data);

            var frms = data.Frms;


            GenerBindDDL("DDL_Frms", frms, "No", "Name", "all");


        });

        //执行保存..
        function Save() {

            var condType = GetQueryString("CondType");
            var fk_flow = GetQueryString("FK_Flow");
            var fk_Node = GetQueryString("FK_Node");
            var fk_mainNode = GetQueryString("FK_MainNode");
            var toNodeID = GetQueryString("ToNodeID");
            var DDL_Fields = $("#DDL_Fields").val(); //  字段.
            var DDL_Operator = $("#DDL_Operator").val(); //  操作符.


            var OperVal = "";

            var tb = document.getElementById("TB_Val");
            if (tb.style.display == "") {
                OperVal = tb.value;
            } else {
                OperVal = $("#DDL_Val").val(); //  操作符.
            }

            var DDL_Frms = $("#DDL_Frms").val();
            if (typeof DDL_Frms == "undefined" || DDL_Frms == "" || DDL_Frms == "all") {
                alert("请选择独立表单");
                return;
            } else if (typeof DDL_Fields == "undefined" || DDL_Fields == "") {
                alert("请选择表单字段");
                return;
            } else if (typeof OperVal == "undefined" || OperVal == "") {
                alert("请选择操作符");
                return;
            }


            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("DDL_Fields", DDL_Fields);
            handler.AddPara("DDL_Operator", DDL_Operator);
            handler.AddPara("OperVal", OperVal);
            handler.AddPara("CondType", condType);
            handler.AddPara("FK_Flow", fk_flow);
            handler.AddPara("FK_Node", fk_Node);
            handler.AddPara("FK_MainNode", fk_mainNode);
            handler.AddPara("ToNodeID", toNodeID);
            handler.AddPara("FrmID", $("#DDL_Frms").val()); //表单ID.
            handler.AddFormData();

            var data = handler.DoMethodReturnString("StandAloneFrm_Save");
            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }
            alert("保存成功");
            Back();
        }

        function changeForm(s) {
            var value = $(s).val();
            if (value == "all") {
                $("#DDL_Fields").empty();
                $("#DDL_Fields").trigger("change");
            } else {
                var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
                handler.AddPara("FrmID", value);
                var data = handler.DoMethodReturnString("StandAloneFrm_InitFrmAttr");

                if (data) {
                    GenerBindDDL("DDL_Fields", JSON.parse(data), "KeyOfEn", "Name");
                    $("#DDL_Fields").trigger("change");
                }
            }
        }

        //当字段选择的时候.
        function changeCond(c) {

            if (c == null || c.value.length == 0 || c.value == "all") {
                $("#DDL_Operator").empty();
                return;
            }

            var key = c.value;

            var fk_flow = GetQueryString("FK_Flow");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond");
            handler.AddPara("KeyOfEn", key);
            handler.AddPara("FK_Flow", fk_flow);
            handler.AddPara("FrmID", $("#DDL_Frms").val());

            var data = handler.DoMethodReturnString("StandAloneFrm_InitField");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html("<font color=red>" + data + "</font>");
                return;
            }

            if (data.indexOf('url@') == 0) {
                var url = data.replace('url@', '');
                window.location.href = url;
                return;
            }

            data = JSON.parse(data);

            //获得 mapattr.
            var mapattr = data["Sys_MapAttr"][0];

            //操作符.
            var opers = data["Opers"];

            //两者都隐藏.
            document.getElementById("TB_Val").style.display = "none";
            document.getElementById("DDL_Val").style.display = "none";

            if (mapattr.LGType == "1") {
                /*是枚举类型*/
                var enums = data["Enums"];

                GenerBindDDL("DDL_Val", enums, "IntKey", "Lab", 0);

                //显示.
                document.getElementById("DDL_Val").style.display = "";

            } else {
                document.getElementById("TB_Val").style.display = "";
            }

            //绑定操作符.
            GenerBindDDL("DDL_Operator", opers, "No", "Name", "=");
        }

        //返回.
        function Back() {
            var url = window.location.href;
            url = url.replace('StandAloneFrm.htm', 'List.htm');

            window.location.href = url;
        }
    </script>
</head>
<body onkeypress="Esc();">
    <form id="cc">
        <div style="right:30px; position:absolute; z-index:100; ">
            <fieldset style="border: 0px;">
                <input type="button" onclick="Back()" value="返回" id="Button2" />
            </fieldset>
        </div>
        <table id="table" style="position:relative;top:10px; margin: 8px; width:100%">
            <caption>
                <img style="margin-bottom:8px;" align="middle" src='../../Img/Event.png' /> 按照独立表单做方向条件
            </caption>
            <tr>
                <td style="width: 20%;">
                    选择独立表单:
                </td>
                <td>
                    <select id="DDL_Frms" name="DDL_Frms" style="width: 400px;" onchange="changeForm(this)">
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;">
                    选择表单字段:
                </td>
                <td>
                    <select id="DDL_Fields" name="DDL_Fields" style="width: 400px;" onchange="changeCond(this)">
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;">
                    操作符:
                </td>
                <td>
                    <select id="DDL_Operator" name="DDL_Operator" style="width: 100px;">
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;">
                    值:
                </td>
                <td>
                    <input type="text" value="" style="width: 100px;" id="TB_Val" name="TB_Val" />
                    <br />
                    <select id="DDL_Val" name="DDL_Val" style="width: 100px;">
                    </select>
                </td>
            </tr>


            <tr>
                <td></td>
                <td>
                    <input type='button' value='保存' onclick='Save();' />
                </td>
            </tr>


        </table>

    </form>
    <center>
        <div id="Msg" />
    </center>
</body>
</html>
